package com.cms.biz.common;

import java.sql.ResultSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.common.util.EMPSQLUtil;
import com.efounder.builder.base.data.DataSetUtils;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.sql.JConnection;
import com.efounder.sql.JStatement;

@Repository
public class EMPContractUtil{
	
	@Autowired
	private JdbcTemplate                    jdbcTemplate;
	
	public EFRowSet getYBHT(String F_HTBH) {
		JConnection      conn = null;
		JStatement       stmt = null;
		ResultSet          rs = null;
		String         strSql = "";
		EFDataSet     dataset = EFDataSet.getInstance("HTZDMX");
		EFRowSet       rowset = EFRowSet.getInstance();
		Double           fkje = 0.0;
		try {
			conn = JConnection.getInstance(jdbcTemplate.getDataSource().getConnection());
			stmt = conn.createStatement();

			strSql = "select F_HTBH,F_HTMC,F_HTJE from HTXXZD where F_HTBH = '" + F_HTBH + "'";
			rs = stmt.executeQuery(strSql);
			dataset = DataSetUtils.resultSet2DataSet(rs, dataset);
			rowset = dataset.getRowSet(0);
			
			strSql = "select round(sum(F_FKJE),2) as F_LJJE from HTFKXX where F_HTBH = '" + F_HTBH + "' and F_DJZT = '1'";
			rs = stmt.executeQuery(strSql);
			if(rs != null && rs.next()) {
				fkje = rs.getDouble("F_LJJE");
			}
			rowset.putNumber("F_LJJE", fkje);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				EMPSQLUtil.closeAllResources(rs, stmt, conn);	
			} catch(Exception ce) {
				ce.printStackTrace();
			}
		}
		return rowset;
	}
}
